<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>User application</title>
    <link rel="stylesheet" href="css/main.css" />
    <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
    <script type="text/javascript" src="xui.js"></script>
    <script type="text/javascript" src="jquery-1.5.min.js"></script>
    
  </head>
  <body>
  	
    <div id="menu" align="center">
  		<p>Menu</p>
  		<p>
  			<button id="regFormBut" class="buttn"> Add information about you</button>
  		</p>
  		<p>
  			<button id="signIn" class="buttn">Sign in</button>
  		</p>
  		<p>
          	<button id="exit" class="buttn">Exit from system</button>
        </p>
  	</div>

    <div align="center" id="sendTable">
		<p>
			<h3>Fill this fields</h3>
		</p>
		<p>
			<label>Name: </label>
			<input id="name" type=text class="formInfo" value="Bob"/>
		</p>
		<p>
			<label>lastname: </label>
			<input id="lastname" type=text class="formInfo" value="Smith"/>
		</p>
		<p>
			<label>zip: </label>
			<input id="zip" type=text class="formInfo" value="48015"/>
		</p>
		<p>
			<label>country: </label>
			<input id="country" type=text class="formInfo" value="USA"/>
		</p>
		<p>
			<label>stateProvince: </label>
			<input id="stateProvince" type=text class="formInfo" value="Massachusett"/>
		</p>
		<p>
			<label>city: </label>
			<input id="city" type=text class="formInfo" value="Boston"/>
		</p>
		<p>
			<label>email: </label>
			<input id="email" type=text class="formInfo" value="bob@hotmail.com"/>
		</p>
		<p>
			<label>phone: </label>
			<input id="phone" type=text class="formInfo" value="911"/>
		</p>
		<p>
			<label>facebook: </label>
			<input id="facebook" type=text class="formInfo" value="something"/>
		</p>
		<p>
			<button id="regBut" class="buttn">Register</button>
		</p>
	</div>
	</body>
</html>
<script type="text/javascript" charset="utf-8">
	var userId;
	var deviceSn="test111";
	var deviceType="devType";
	
	
    x$('#regFormBut').on('click',function(p){
    	document.getElementById('menu').style.display = "none";
    	document.getElementById('sendTable').style.display = "inline"; 
	});
	
    x$('#signIn').on('click',function(p){
    	window.location="signIn.html";
   	});
    
    x$( '#regBut' ).on( 'click', function(e) {
    
 		var name = x$("#name").attr('value');
   	 	var lastname = x$("#lastname").attr('value');
   	 	var email = x$("#email").attr('value');
   	 	var zip = x$("#zip").attr('value');
   	 	var city = x$("#city").attr('value');
   	 	var stateProvince = x$("#stateProvince").attr('value');
   	 	var country = x$("#country").attr('value');
   	 	var facebook = x$("#facebook").attr('value');
   	 	var phone = x$("#phone").attr('value');
   	 	
   	 	
 		x$("#returned_information").xhr("http://10.0.2.2:9000/user/registration?name="+name+"&lastname="+lastname+"&email="+email+"&zip="+zip+
   	 		"&city="+city+"&stateProvince="+stateProvince+"&country="+country+"&facebook="+facebook+"&phone="+phone+"&deviceType="+deviceType+
   	 		"&deviceSn="+deviceSn, 
        { callback: function()
          {
          	  if(this.responseText == 1){
	          	alert("registration error. User with this deviceSn already exist, click signIn");
	          	document.getElementById('menu').style.display = "inline";
    			document.getElementById('sendTable').style.display = "none"; 
    		  }
	          if(this.responseText == 0){
	          	alert("registration success");
	          	document.getElementById('menu').style.display = "inline";
    			document.getElementById('sendTable').style.display = "none"; 
	          }
	       	}
        });                   
     
	});
	 $('#exit').click(function(p){
   	    navigator.app.exitApp();
    });
</script>